{
 "metadata": {
  "name": ""
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "This is an experiment to see how to create a Drop class that is used to track all operations performed on an object (as it happens, an event object, such as mouse position, key pressed, etc)."
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "http://docs.python.org/2/reference/datamodel.html#emulating-numeric-types"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "class Drop(object):\n",
      "    def __init__(self, name=''):\n",
      "        self._spy = []\n",
      "        self._name = name\n",
      "    def _op(self, fun, args=()):\n",
      "        self._spy.append((fun, args, ))\n",
      "    def __add__(self, b):\n",
      "        self._op('__add__', (self, b))\n",
      "        return self\n",
      "    def _show_spy(self):\n",
      "        return '\\n'.join('{fun}(*{args})'.format(fun=fun, args=args)\n",
      "                         for (fun, args) in self._spy)\n",
      "    def __repr__(self):\n",
      "        return self._name\n",
      "a = Drop('a')\n",
      "b = Drop('b')\n",
      "print a\n",
      "print b\n",
      "print (a+b)._show_spy()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "a\n",
        "b\n",
        "__add__(*(a, b))\n"
       ]
      }
     ],
     "prompt_number": 31
    }
   ],
   "metadata": {}
  }
 ]
}